package Day2025_03_02;

import java.util.HashMap;
import java.util.Map;

public class LeetCode1 {
    public int[] twoSum(int[] nums, int target) {
        int n = nums.length;
        int[] ret = new int[2];
        Map<Integer, Integer> hash = new HashMap<>();
        for (int i = 0; i < n; i++) hash.put(target - nums[i], i);
        for (int i = 0; i < n; i++) {
            if (hash.containsKey(nums[i]) && hash.get(nums[i]) != i) {
                ret[0] = i;
                ret[1] = hash.get(nums[i]);
                break;
            }
        }
        return ret;
    }
}
